package com.tdk.bts.view.manager;

import java.awt.Cursor;
import java.awt.Font;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import com.tdk.bts.action.BookInfoAction;
import com.tdk.bts.util.ImageUtil;
import com.tdk.bts.util.Request;
import com.tdk.bts.vo.BookInfoVO;

public class GetTicketView extends BaseTabbedPanel {
	private JTextField phoneField;
	private JTextField validCodeField;
	
	private BookInfoAction bookInfoAction = new BookInfoAction();
	
	public GetTicketView() {
		
		Font textFont = new Font("宋体", Font.BOLD, 20);
		
		setLayout(null);
		setSize(800,600);
		
		JLabel phoneLabel = new JLabel("手机号");
		phoneLabel.setFont(textFont);
		phoneLabel.setBounds(206, 150, 95, 50);
		add(phoneLabel);
		
		phoneField = new JTextField();
		phoneField.setFont(textFont);
		phoneField.setBounds(308, 150, 275, 50);
		add(phoneField);
		phoneField.setColumns(10);
		
		JLabel validCodeLabel = new JLabel("取票码");
		validCodeLabel.setFont(textFont);
		validCodeLabel.setBounds(210, 232, 91, 50);
		add(validCodeLabel);
		
		validCodeField = new JTextField();
		validCodeField.setFont(textFont);
		validCodeField.setBounds(308, 232,  275, 50);
		add(validCodeField);
		validCodeField.setColumns(10);
		
		JLabel submitLabel = new JLabel();
		submitLabel.setIcon(ImageUtil.getImage("submitBtn.png"));
		submitLabel.setBounds(331, 348, 99, 33);
		add(submitLabel);
		
		
		submitLabel.setCursor(new Cursor(Cursor.HAND_CURSOR));
		submitLabel.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				
				Request request = new Request();
				request.setParameter("phone", phoneField.getText());
				request.setParameter("validCode", validCodeField.getText());
				
				try {
					//调用action方法取标，并把取标信息存储在request中
					bookInfoAction.getTicket(request);
					BookInfoVO vo = (BookInfoVO) request.getAttribute("bookInfo");
					StringBuffer msg = new StringBuffer()
							.append("<html>")
							.append("您已经取出了			")					
							.append("<ul>					")			
							.append("	<li>电影:"+vo.getFilmName()+"</li>		")						
							.append("	<li>放映时间:"+vo.getStartDay()+ " " + vo.getStartTime()+"</li>	")							
							.append("	<li>放映厅:"+vo.getTheaterName()+"</li>	");						
					for (int i = 0; i < vo.getBookInfos().size(); i++) {
						msg.append("    <li>"+(vo.getBookInfos().get(i).getSeatX()+1)+"排"+(vo.getBookInfos().get(i).getSeatY()+1)+"号</li>      ");
					}
					msg.append("	</ul>					")			
							.append("的票！					")
							.append("</html>");
					JOptionPane.showMessageDialog(null, new JLabel(msg.toString()), "提示", JOptionPane.INFORMATION_MESSAGE);
				} catch (Exception e1) {
					JOptionPane.showMessageDialog(null, e1.getMessage(), "错误", JOptionPane.ERROR_MESSAGE);
				}
				
				/*
		select start_day,start_time,film.name,screen.name,seat_x,seat_y
		from t_film_screen screen,t_film film,t_book_info book
		where book.screen_id=screen.id and screen.film_id=film.id;
		
				 * 
				 * */
				
			}
		});
	}

	@Override
	public void bindData(int pageNo) {
		
	}
}
